package com.zline.foodraise.ui.activity;

import android.graphics.Bitmap;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.zline.foodraise.R;
import com.zline.foodraise.js.MyWebViewSetting;
import com.zline.foodraise.util.LUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringRes;

/**
 * Created by heshantao on 15/8/31.
 * 筹店入驻协议
 */
@EActivity(R.layout.activity_protocol)
public class ProtocolActivity extends ZlineActivity {
    private static final String LOG_TAG = ProtocolActivity.class.getSimpleName();
    @ViewById(R.id.protocol_wv)
    WebView wv;
    MyWebViewSetting mSetting;
    @StringRes(R.string.protocol_title)
    String title;
    @ViewById(R.id.app_common_header_title_tv)
    TextView title_iv;

    @AfterViews
    void doSomeAfterViews() {
        initHeader();
        initWebView();
    }

    void initHeader() {
        title_iv.setText(title);
    }

    void initWebView() {
        mSetting = new MyWebViewSetting(wv, this);
        mSetting.setWebView();
        wv.loadUrl("file:///android_asset/protocol.html");
        wv.setWebViewClient(new WebViewClient() {
            //出错界面
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                LUtil.i(LOG_TAG, "______________erroCode________" + description);
            }


            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                LUtil.i(LOG_TAG, "_________shouldOverrideUrlLoading________" + url);
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                LUtil.i(LOG_TAG, "_________onPageStarted________" + url);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                LUtil.i(LOG_TAG, "____Host_____onPageFinished________" + url);
                if (!view.getSettings().getLoadsImagesAutomatically()) {
                    view.getSettings().setLoadsImagesAutomatically(true);
                }
            }
        });
    }

    @Click(R.id.app_common_header_left_icon_iv)
    void onClick() {
        goback();
    }

}
